﻿namespace ExamV5.OnLineInter
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class LookQuestInfo : Page
    {
        protected Button butDefault;
        protected GridView DataGridInfo;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        protected HyperLink HLLook;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        protected Label labDCUserCode;
        protected Label labEndTime;
        protected Label labIsAnyUser;
        protected Label labIsIP;
        protected Label labIsLook;
        protected Label labTitleInfo;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected UpdatePanel UPPart;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            if (this.publicFun_0.GetValues(string.Concat(new object[] { "select ChooseTime from QuestUser where DCID=", this.int_0, " and ChooseUserCode='", this.httpCookie_0.Value, "'" }), "ChooseTime").Trim() != "")
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckD", "alert('您已经投票，无法再进行投票！')", true);
            }
            else
            {
                string strSql = "";
                string str4 = "";
                string str5 = Convert.ToString(base.Request.ServerVariables["Remote_Addr"]);
                for (int i = 0; i < this.DataGridInfo.Rows.Count; i++)
                {
                    RadioButtonList list2 = (RadioButtonList) this.DataGridInfo.Rows[i].FindControl("RBLAData");
                    CheckBoxList list = (CheckBoxList) this.DataGridInfo.Rows[i].FindControl("CBLBData");
                    TextBox box = (TextBox) this.DataGridInfo.Rows[i].FindControl("txtWrite");
                    Label label = (Label) this.DataGridInfo.Rows[i].FindControl("labID");
                    if (list2.Visible)
                    {
                        if (list2.SelectedIndex == -1)
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckE", "alert('投票选项有未选择项！')", true);
                            return;
                        }
                        str4 = list2.SelectedItem.Value;
                    }
                    if (list.Visible)
                    {
                        if (list.SelectedIndex == -1)
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckF", "alert('投票选项有未选择项！')", true);
                            return;
                        }
                        str4 = "#";
                        for (int j = 0; j < list.Items.Count; j++)
                        {
                            if (list.Items[j].Selected)
                            {
                                str4 = str4 + list.Items[j].Value + "#";
                            }
                        }
                    }
                    if (box.Visible)
                    {
                        if (box.Text.Trim() == "")
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckG", "alert('投票内容未填写！')", true);
                            return;
                        }
                        str4 = base.Server.HtmlEncode(box.Text).Replace("\n", " <br/>").Replace(" ", " ").Replace("'", "‘").Replace(";", "；");
                    }
                    strSql = string.Concat(new object[] { strSql, "insert into QuestUser(DCID,ItemID,ChooseValue,ChooseUserCode,ChooseUserName,ChooseIP) values(", this.int_0, ",", label.Text, ",'", str4, "','", this.httpCookie_0.Value, "','", this.httpCookie_1.Value, "','", str5, "');" });
                }
                if (strSql.Trim().Length > 1)
                {
                    this.publicFun_0.ExecuteSql(strSql);
                    string str3 = base.Request.Url.ToString();
                    str3 = str3.Substring(0, str3.LastIndexOf('/') + 1);
                    base.Response.Redirect(str3 + "LookResult.aspx?ID=" + this.int_0);
                }
            }
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label label = (Label) e.Row.Cells[0].FindControl("labItemInfo");
                Label label2 = (Label) e.Row.Cells[0].FindControl("labIsSing");
                RadioButtonList list2 = (RadioButtonList) e.Row.Cells[0].FindControl("RBLAData");
                CheckBoxList list = (CheckBoxList) e.Row.Cells[0].FindControl("CBLBData");
                TextBox box = (TextBox) e.Row.Cells[0].FindControl("txtWrite");
                if (label2.Text.Trim() != "Y")
                {
                    if (!(label2.Text.Trim() == "N"))
                    {
                        list2.Visible = false;
                        list.Visible = false;
                        box.Visible = true;
                    }
                    else
                    {
                        list2.Visible = false;
                        list.Visible = true;
                        box.Visible = false;
                    }
                }
                else
                {
                    list2.Visible = true;
                    list.Visible = false;
                    box.Visible = false;
                }
                if (label2.Text.Trim() != "Z")
                {
                    string[] strArray = label.Text.Trim().Split(new char[] { '#' });
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        if (strArray[i].Trim() != "")
                        {
                            ListItem item = new ListItem(strArray[i], i.ToString());
                            if (list2.Visible)
                            {
                                list2.Items.Add(item);
                            }
                            else
                            {
                                list.Items.Add(item);
                            }
                        }
                    }
                }
            }
        }

        private void method_0()
        {
            this.DataGridInfo.Visible = true;
            string selectCommandText = "select * from QuestItem where DCID=" + this.int_0;
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "OnlineQuest");
            this.DataGridInfo.DataSource = dataSet.Tables["OnlineQuest"].DefaultView;
            this.DataGridInfo.DataBind();
        }

        private void method_1()
        {
            string values = this.publicFun_0.GetValues(string.Concat(new object[] { "select ChooseTime from QuestUser where DCID=", this.int_0, " and ChooseUserCode='", this.httpCookie_0.Value, "'" }), "ChooseTime");
            if (!(values.Trim() == ""))
            {
                this.butDefault.Visible = false;
            }
            else
            {
                this.butDefault.Visible = true;
            }
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand("select ID,TitleInfo,EndTime,DCUserCode,DCUserName,IsAnyUser,IsLook,IsIP,CreatUser,CreatTime,Status from OnlineQuest where ID=" + this.int_0, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                this.HLLook.NavigateUrl = "LookResult.aspx?ID=" + this.int_0;
                this.labTitleInfo.Text = reader["TitleInfo"].ToString();
                this.labEndTime.Text = reader["EndTime"].ToString();
                this.labIsIP.Text = reader["IsIP"].ToString();
                this.labDCUserCode.Text = reader["DCUserCode"].ToString();
                this.labIsAnyUser.Text = reader["IsAnyUser"].ToString();
                this.labIsLook.Text = reader["IsLook"].ToString();
                if (reader["Status"].ToString() == "C")
                {
                    this.butDefault.Visible = false;
                }
                if (!((reader["DCUserCode"].ToString().Trim().IndexOf("所有人员") == -1) ? (reader["DCUserCode"].ToString().Trim().IndexOf("," + this.httpCookie_0.Value + ",") != -1) : true))
                {
                    this.butDefault.Visible = false;
                }
                if (reader["IsLook"].ToString().Trim() != "Y")
                {
                    if (reader["IsLook"].ToString().Trim() == "Z")
                    {
                        this.HLLook.Visible = false;
                    }
                    else if (values != "")
                    {
                        this.HLLook.Visible = true;
                    }
                }
                else
                {
                    this.HLLook.Visible = true;
                }
                string str2 = Convert.ToString(base.Request.ServerVariables["Remote_Addr"]);
                if ((reader["IsIP"].ToString().Trim() == "Y") && (this.publicFun_0.GetValues(string.Concat(new object[] { "select ChooseTime from QuestUser where DCID=", this.int_0, " and ChooseIP='", str2, "'" }), "ChooseTime") != ""))
                {
                    this.butDefault.Visible = false;
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckA", "alert('此IP已投票，无法再进行投票！')", true);
                }
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
                base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---在线投票中心";
                if (!base.IsPostBack)
                {
                    if (!(this.publicFun_0.ReturnPaperData() != "Yes"))
                    {
                        this.butDefault.Attributes.Add("onclick", "javascript:{if(confirm('确定进行投票,确定后将无法修改？')==false) return false;}");
                        this.method_1();
                        this.method_0();
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                    }
                }
            }
        }
    }
}

